Maven Project Object Model
https://maven.apache.org/pom.html
项目对象模型
采用xml描述项目的所有配置信息。
Super POM
Super POM是Maven项目的默认设置,Maven项目的POM文件继承自Super POM,项目文件中的设置将覆盖默认设置。
默认仓库
<repositories> <!-- <pluginRepositories> 也是同一地址 -->
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Maven – Settings Reference (apache.org): certain settings such as username
and password
should not be distributed along with the pom.xml
. This type of information should exist on the build server in the settings.xml
.
变量
Any field of the model that is a single value element can be referenced as a variable.
特殊变量
变量 | 含义 |
---|---|
元素说明
Maven Model – Maven (apache.org)
项目信息
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--unique id: groupId-artifactId-version-->
<groupId>gary.deeplearning4j</groupId> <!--unique org ID-->
<artifactId>dl4j-start-app</artifactId> <!--project name-->
<version>1.0.0.0</version>
<packaging>jar</packaging> <!--pom for parent project-->
<!--Information of project-->
<name>DeepLearning4j Start</name>
<url>http://deaplearning.gary.net</url>
<description>
The start application for learning the Deeplearnig4J project.
</description >
<properties>...</properties>
<dependency>...</dependency>
<build>....</build>
</project>
POM信息
标签 | 说明 |
---|---|
project | 根元素:声明POM的XML 命名空间。 |
modelVersion | POM版本,通常为4.0.0,不常变化 |
项目信息
标签 | 说明 |
---|---|
groupId | 创建项目的组织名称,通常基于有效的组织域名。 |
artifactId | 输出文件名称。 |
packaging | 输出文件打包格式(默认为*.jar )。 |
version | 输出文件版本。 |
name | 项目的显示名称。 |
url | 项目的网站。 |
description | 项目的描述信息。 |
modules | 多项目管理。 |
parent | 多项目的父项目信息。 |
licences | |
organization | |
developers | |
contributors |
环境变量
获取环境变量:
env.PATH
:返回系统环境变量;
project.X.Y
:返回POM.xml
中对应元素的值;
settings.xxx
:获取settings.xml
中元素的值;
Java环境变量,例如${java.home}
;
xxx.yyy.zzz
:在properties
标签中设置的元素。
标签 | 说明 |
---|---|
properties | 声明环境变量用于在文件其他部分进行替换(${dl4j.version} )。作为过滤器。 |
maven.compiler.source maven.compiler.target | 为Maven的编译任务指定Java版本(例如1.8 ,11 )。 |
<!--Define enviromnment variables for Maven-->
<properties>
<nd4j.version>1.0.0-beta4</nd4j.version>
<dl4j.version>1.0.0-beta4</dl4j.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
特殊变量:${project.basedir}
项目根目录。
依赖库
标签 | 说明 |
---|---|
dependencies | 依赖库列表,其子元素为dependency 。 |
dependency | 依赖库声明,其子元素包括:groupId 、artifactId 和version 。依赖库的信息可以在Maven软件仓库中查询。 |
dependencyManagement | 用于父项目管理依赖项配置。 |
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>${nd4j.backend}</artifactId>
<version>${nd4j.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nlp</artifactId>
<version>${dl4j.version}</version>
</dependency>
</dependencies>
构建工具配置
标签 | 说明 |
---|---|
build | 构建工具配置。 |
plugins | 位于build 子节点,构建工具列表。 |
pluginManagement | 位于build 子节点,其子节点plugins/plugin 声明全局的插件配置信息,任何子项目要使用其中的插件还需要在build/plugins 子节点中声明。 |
plugin | 构建工具声明,包括工具的groupId 、artifactId 、version 以及相关配置信息。 |
configuration | 构建工具配置信息,其包含的子元素取决于具体工具。 |
executions | 指定构建工具的执行方式。 |
resources | specifying where resources exist within your project. |
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
<defaultGoal>install</defaultGoal> <!--default goal/phase to execute-->
<directory>${basedir}/target</directory> <!--output dir-->
<finalName>${artifactId}-${version}</finalName> <!--output name-->
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>gary.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>